package com.eleadmin.order.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.order.entity.ContainerBill;
import com.eleadmin.order.entity.Ocean;
import com.eleadmin.order.param.OceanParam;
import com.eleadmin.order.service.OceanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * 海运
 * @author : Doman
 * @date : 2023-04-24 11:26:09
 * @version ：1.0
 */

@Api(tags = "海运")
@RestController
@RequestMapping("/api/order/ocean")
public class OceanController extends BaseController {

    @Autowired
    private OceanService oceanService;

    @PreAuthorize("hasAuthority('order:ocean:list')")
    //@ApiOperation("分页查询海运")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Ocean ocean) throws Exception{
        return oceanService.list(page, ocean, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:ocean:list')")
    //@ApiOperation("查询全部海运")
    @GetMapping()
    public JsonResult list(OceanParam ocean){
        return oceanService.list(ocean, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:ocean:list')")
    //@ApiOperation("根据id查询海运")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return oceanService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:ocean:save')")
    @OperationLog
    @ApiOperation(value ="添加海运")
    @PostMapping()
    public JsonResult save(@RequestBody Ocean ocean) {
        try {
            return oceanService.save(ocean, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:ocean:update')")
    @OperationLog
    @ApiOperation(value ="修改海运")
    @PutMapping()
    public JsonResult update(@RequestBody Ocean ocean) {
        try {
            return oceanService.update(ocean, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:ocean:remove')")
    @OperationLog
    @ApiOperation(value ="删除海运")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return oceanService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:customer:exportsCustomer')")
    @ApiOperation("导出客户海运账单")
    @GetMapping("/exportsOcean")
    public void exportsOcean(Ocean ocean, HttpServletResponse response, HttpServletRequest request) throws Exception{
        oceanService.exportsOcean(ocean, getLoginUser(),response, request);
    }

    @PreAuthorize("hasAuthority('order:customer:exportsFinance')")
    @ApiOperation("应收应付分类导出财务报表")
    @GetMapping("/exportsFinance")
    public void exportsFinance(Ocean ocean, HttpServletResponse response, HttpServletRequest request) throws Exception{
        oceanService.exportsFinance(ocean, getLoginUser(),response, request);
    }


}
